# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from movieproject.mysql import Mp4BaSql
from movieproject.items import MovieItem,MovieDetailItem

class MovieSavePipeline(object):
    def __init__(self):
        self.linecount = 0
        self.db = Mp4BaSql()

    def process_item(self, item, spider):
        self.linecount  = self.linecount +1

        if type(item) is MovieItem:
            print "%d.\t%s" %(self.linecount,item['name'])
            self.db.insert('tbMovieItem',item)
        elif type(item) is MovieDetailItem:
            print item['download_link']
            self.db.insert('tbMovieDetailItem',item)
        else:   
            pass
        return item
